#pragma once

#include "GTASprite.h"
#include "GTAMoveBoard.h"

class GTABoard
{
private:
	enum
	{
		BLOCK_SIZE_X = 30,
		BLOCK_SIZE_Y = 30,

		BOARD_WIDTH = 21,
		BOARD_HEIGHT = 21,

		BOARD_START_X = 69,
		BOARD_START_Y = 69,

		LEFT = 1,
		RIGHT = 2,
				
		EMPTYSPACE = 0,
		BLOCK = 1,
		CORE = 2
	};

public:
	GTABoard(void);
	~GTABoard(void);

	bool Init(void);

	void Update(GTAMoveBoard* moveBoard);
	void Render(void);

	void RotateLeft(void);
	void RotateRight(void);
	void FixBlock(void);
	void IsMove(int cx, int cy);
	bool IsInBlock(int cx, int cy);

private:
	bool _InitBlockSprite(void);
	bool _InitCoreSprite(void);

	void _CalcBlockLength(void);
	bool _IsRotatAble(int direction);
	void _Rotate(int direction);

	bool _IsTopOver(int tempMoveY);
	bool _IsLeftOver(int tempMoveX);
	bool _IsRightOver(int tempMoveX);
	bool _IsBottomOver(int tempMoveY);
	
	void _SetCrashDirection(GTAMoveBoard* moveBoard, int& crashY, int& crashX);
	bool _IsCollision(GTAMoveBoard* moveBoard, int crashX, int crashY);

	void _ShutDown(void);
	
private:
	GTASprite*	mBlockSprite;
	GTASprite*	mCoreSprite;

	int mGameBoard[BOARD_HEIGHT][BOARD_WIDTH];

	int mBeginWidth;
	int mEndWidth;
	int mBeginHeight;
	int mEndHeight;
	int mCoreWidth;
	int mCoreHeight;

	int mClickedX;
	int mClickedY;

	int mMoveX;
	int mMoveY;
};
